//随机生成颜色

let color = {
  colorArr: [],
  hsvtorgb: function (h, s, v) { //hsv转rgb
    let h_i = parseInt(h * 6);
    let f = h * 6 - h_i;
    let p = v * (1 - s);
    let q = v * (1 - f * s);
    let t = v * (1 - (1 - f) * s);
    let r, g, b;
    switch (h_i) {
      case 0:
        r = v;
        g = t;
        b = p;
        break;
      case 1:
        r = q;
        g = v;
        b = p;
        break;
      case 2:
        r = p;
        g = v;
        b = t;
        break;
      case 3 :
        r = p;
        g = q;
        b = v;
        break;
      case 4:
        r = t;
        g = p;
        b = v;
        break;
      case 5:
        r = v;
        g = p;
        b = q;
        break;
      default:
        r = 1;
        g = 1;
        b = 1;
    }
    return 'rgb(' + parseInt(r * 255) + ',' + parseInt(g * 255) + ',' + parseInt(b * 255) + ',1)'
  },
  setColorArr: function (le) { //h和s值固定，随机生成v
    this.colorArr = new Array;
    let golden_ratio = 0.618033988749895;
    let s = 0.5;
    let v = 0.999;
    for (let i = 0; i < le; i++) {
      let h = golden_ratio + Math.seededRandom(-0.5, 0.3);
      let color = this.hsvtorgb(h, s, v);
      this.colorArr.push(color)
    }
  }
}

Math.seed = 7;

Math.seededRandom = function(max, min) {//伪随机数
  max = max || 1;
  min = min || 0;
  Math.seed = (Math.seed * 9301 + 49297) % 233280;
  var rnd = Math.seed / 233280.0;
  return min + rnd * (max - min);
};

export default color



